package com.wsz.cloud.core.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.wsz.cloud.core.entity.UserInfo;

@RestController
public class MoveController {

	@Autowired
	private RestTemplate restTemplate;
	
	@HystrixCommand(fallbackMethod = "findUserInfoFallback", commandProperties = {@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")})
	@GetMapping("/movie/{id}")
	public UserInfo findUserInfo(@PathVariable Long id) {
		return restTemplate.getForObject("http://microserver-provider-user/simple/"+id, UserInfo.class);
	}
	
	public UserInfo findUserInfoFallback(Long id) {
		UserInfo userInfo = new UserInfo();
		userInfo.setId(-1L);
		return userInfo;
	}
}
